package 序列化与反序列化;

import java.io.*;

public class SerializeableDemo {
    public static void main(String[] args) {
        User user = new User();
        user.setName("wang");
        System.out.println(user);
        try {
            FileOutputStream fos = new FileOutputStream("tempFile");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(user);

        } catch (IOException e) {
            e.printStackTrace();
        }

        File file = new File("tempFile");
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
            User newUser = (User)ois.readObject();
            System.out.println(newUser);
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }


    }

}
